<?php
require_once 'Zend/Controller/Action.php';

class Naneau_Controller_Action extends Zend_Controller_Action {

    /**
     * encode a response string and send it as JSON
     *
     * @param mixed $response the string to encode
     * @param bool $useHeader put the result in an X-JSON header
     * @return void
     */
    protected function sendJsonResponse($response, $useHeader = false) {
        $this->_helper->viewRenderer->setNeverRender();
        $this->_helper->viewRenderer->setNoRender();
        //stop view renderer from being... bad
        
        Zend_Loader::loadClass('Zend_Json');
        $json = Zend_Json::encode($response);
        //encode the result

        if ($useHeader) {
            $this->getResponse()->setHeader('X-JSON', $json);
            $this->getResponse()->setBody('');
        }
        else {
            $this->getResponse()->setHeader('Content-Type', 'text/javascript');
            $this->getResponse()->setBody($json);
        }
        //encode result
    }

}